package com.apex.aolonfitdemo.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSONObject;
import com.apex.aolonfit.AolonFitManager;
import com.apex.aolonfitdemo.R;
import com.apex.aolonfitdemo.databinding.ActivitySyncMonitorDataBinding;
import com.apex.aolonfitdemo.dialog.PriorityDialog;
import com.apex.aolonfitdemo.dialog.WaitingDialog;
import com.apex.ax_bluetooth.callback.GeneralCallback;
import com.apex.ax_bluetooth.core.EABleManager;
import com.apex.ax_bluetooth.enumeration.EABleConnectState;
import com.apex.ax_bluetooth.enumeration.MotionReportType;
import com.cyber.bridge.module.bean.BloodOxygenInfoEntity;
import com.cyber.bridge.module.bean.ExerciseInfoEntity;
import com.cyber.bridge.module.bean.HeartRateInfoEntity;
import com.cyber.bridge.module.bean.SleepInfoEntity;
import com.cyber.bridge.module.bean.StepInfoEntity;
import com.cyber.bridge.module.bean.StressInfoEntity;
import com.cyber.bridge.module.callback.OnCyberDataCallBack;

import java.util.List;


public class SyncMonitorDataActivity extends AppCompatActivity {
    private final String TAG = this.getClass().getSimpleName();
    private PriorityDialog priorityDialog;
    ActivitySyncMonitorDataBinding activitySyncMonitorDataBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activitySyncMonitorDataBinding = ActivitySyncMonitorDataBinding.inflate(getLayoutInflater());
        setContentView(activitySyncMonitorDataBinding.getRoot());
        activitySyncMonitorDataBinding.tool.setNavigationIcon(com.apex.aolonfitdemo.R.mipmap.exit_page);
        setSupportActionBar(activitySyncMonitorDataBinding.tool);
        getSupportActionBar().setTitle(null);
        activitySyncMonitorDataBinding.tool.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        activitySyncMonitorDataBinding.prioritySync.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (priorityDialog == null) {
                    priorityDialog = new PriorityDialog(SyncMonitorDataActivity.this);
                    priorityDialog.setSelectListener(new PriorityDialog.SelectListener() {
                        @Override
                        public void selectData(String sex) {

                            activitySyncMonitorDataBinding.prioritySync.setText(sex);
                            if (sex.equalsIgnoreCase(getString(R.string.priority_sync_daily))) {
                                AolonFitManager.getInstance().setStepDataCallBack(new OnCyberDataCallBack<List<StepInfoEntity>>() {
                                    @Override
                                    public void callBack(List<StepInfoEntity> stepInfoEntities) {
                                        if (stepInfoEntities != null) {
                                            Log.e("step", JSONObject.toJSONString(stepInfoEntities));
                                        }
                                    }
                                });
                                AolonFitManager.getInstance().syncStepData();

                            } else if (sex.equalsIgnoreCase(getString(R.string.priority_sync_sleep))) {
                                AolonFitManager.getInstance().setSleepDataCallBack(new OnCyberDataCallBack<List<SleepInfoEntity>>() {
                                    @Override
                                    public void callBack(List<SleepInfoEntity> sleepInfoEntities) {
                                        if (sleepInfoEntities != null) {
                                            Log.e("sleep", JSONObject.toJSONString(sleepInfoEntities));
                                        }
                                    }
                                });
                                AolonFitManager.getInstance().syncSleepData();
                            } else if (sex.equalsIgnoreCase(getString(R.string.priority_sync_heart_rate))) {
                                AolonFitManager.getInstance().setHeartRateDataCallBack(new OnCyberDataCallBack<List<HeartRateInfoEntity>>() {
                                    @Override
                                    public void callBack(List<HeartRateInfoEntity> heartRateInfoEntities) {
                                        if (heartRateInfoEntities != null) {
                                            Log.e("heart", JSONObject.toJSONString(heartRateInfoEntities));
                                        }
                                    }
                                });
                                AolonFitManager.getInstance().syncHeartRateData();
                            }
                            if (sex.equalsIgnoreCase(getString(R.string.priority_sync_multi))) {
                                AolonFitManager.getInstance().setExerciseDataCallBack(new OnCyberDataCallBack<List<ExerciseInfoEntity>>() {
                                    @Override
                                    public void callBack(List<ExerciseInfoEntity> exerciseInfoEntities) {
                                        if (exerciseInfoEntities != null) {
                                            Log.e("exercise", JSONObject.toJSONString(exerciseInfoEntities));
                                        }
                                    }
                                });
                                AolonFitManager.getInstance().syncExerciseData();
                            } else if (sex.equalsIgnoreCase(getString(R.string.priority_sync_blood))) {
                                AolonFitManager.getInstance().setBloodOxygenDataCallBack(new OnCyberDataCallBack<List<BloodOxygenInfoEntity>>() {
                                    @Override
                                    public void callBack(List<BloodOxygenInfoEntity> bloodOxygenInfoEntities) {
                                        if (bloodOxygenInfoEntities != null) {
                                            Log.e("blood", JSONObject.toJSONString(bloodOxygenInfoEntities));
                                        }
                                    }
                                });
                                AolonFitManager.getInstance().syncBloodOxygenData();
                            } else if (sex.equalsIgnoreCase(getString(R.string.priority_sync_stress))) {
                                AolonFitManager.getInstance().setStressDataCallBack(new OnCyberDataCallBack<List<StressInfoEntity>>() {
                                    @Override
                                    public void callBack(List<StressInfoEntity> stressInfoEntities) {
                                        if (stressInfoEntities != null) {
                                            Log.e("stress", JSONObject.toJSONString(stressInfoEntities));
                                        }
                                    }
                                });
                                AolonFitManager.getInstance().syncStressData();
                            }
                        }
                    });
                }
                if (!priorityDialog.isShowing()) {
                    priorityDialog.show();
                }

            }
        });
    }

}
